import { takeEvery, put } from 'redux-saga/effects'
import axios from 'axios'
import {loadDataSync} from './actionCreator'
import {loadDataUserDoctorSync} from './actionCreator'

function* loadDataUser(action) {
    const result = yield axios.get(
        '/api/user'
    )
    yield put(loadDataSync(result.data[0]))
}

function* loadDataUserDoctor(action) {
    const result = yield axios.get(
        '/api/doctorTeam?id='+action.id
    )
    console.log(result)
    yield put(loadDataUserDoctorSync(result.data[0]))
}

function* HomeSaga() {
    yield takeEvery('loadDataUserSaga', loadDataUser)
    yield takeEvery('loadDataUserDoctorSaga', loadDataUserDoctor)
}

export default HomeSaga